home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / date / tcom / tcselcom.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-08  |  2.0 KB  |  98 lines

  1. unit Tcselcom;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, ExtCtrls, Buttons, AdPort;
  8.  
  9. type
  10.   TComSelectForm = class(TForm)
  11.     Label1: TLabel;
  12.     Label2: TLabel;
  13.     OkBtn: TBitBtn;
  14.     AbortBtn: TBitBtn;
  15.     Ports: TGroupBox;
  16.     Com1Btn: TRadioButton;
  17.     Com2Btn: TRadioButton;
  18.     Com3Btn: TRadioButton;
  19.     Com4Btn: TRadioButton;
  20.     Com5Btn: TRadioButton;
  21.     Com6Btn: TRadioButton;
  22.     Com7Btn: TRadioButton;
  23.     Com8Btn: TRadioButton;
  24.     ThePort: TApdComPort;
  25.     procedure FormCreate(Sender: TObject);
  26.   private
  27.     PortButtons : array[1..8] of TRadioButton;
  28.  
  29.     function ValidComPort(ComNumber : Word) : Boolean;
  30.       {-Return TRUE if ComNumber represents a valid port}
  31.  
  32.   public
  33.     function SelectedCom : String;
  34.   end;
  35.  
  36. implementation
  37.  
  38. {$R *.DFM}
  39.  
  40. procedure TComSelectForm.FormCreate(Sender: TObject);
  41. var
  42.   I : Word;
  43.   E : Boolean;
  44.  
  45. begin
  46.   PortButtons[1] := Com1Btn;
  47.   PortButtons[2] := Com2Btn;
  48.   PortButtons[3] := Com3Btn;
  49.   PortButtons[4] := Com4Btn;
  50.   PortButtons[5] := Com5Btn;
  51.   PortButtons[6] := Com6Btn;
  52.   PortButtons[7] := Com7Btn;
  53.   PortButtons[8] := Com8Btn;
  54.  
  55.   E := False;
  56.   for I := 1 to 8 do
  57.     if not ValidComPort(I) then
  58.       PortButtons[I].Enabled := False
  59.     else begin
  60.       PortButtons[I].Enabled := True;
  61.  
  62.       if not E then begin
  63.         PortButtons[I].Checked := True;
  64.         E := True;
  65.       end;
  66.     end;
  67. end;
  68.  
  69. function TComSelectForm.ValidComPort(ComNumber : Word) : Boolean;
  70.   {-Return TRUE if ComNumber represents a valid port}
  71. begin
  72.   Result := True;
  73.  
  74.   try
  75.     ThePort.ComNumber := ComNumber;
  76.     ThePort.Open      := True;
  77.     ThePort.Open      := False;
  78.   except
  79.     Result := False;
  80.   end;
  81. end;
  82.  
  83. function TComSelectForm.SelectedCom : String;
  84. var
  85.   I : Word;
  86.  
  87. begin
  88.   Result := 'COM1';
  89.   for I := 1 to 8 do
  90.     if PortButtons[I].Checked then begin
  91.       Result[4] := Char(I + Ord('0'));
  92.       Exit;
  93.     end;
  94. end;
  95.  
  96. end.
  97.  
  98.